package com.ea.eadp.nexus.test.pageDefinition;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import com.ea.eadp.nexus.test.common.PageOperation;
import com.ea.eadp.nexus.test.common.TestUtil;

public class AccountUpgradeWeb2 extends BasePage {
    public AccountUpgradeWeb2(WebDriver driver, final String userCode, final String email) {
        super(driver, AccountUpgradeWeb2.class);
        this.setUri(TestUtil.getWeb2AccountUpgradeUrl(userCode, email));
    }

    public void setUpgradeOriginId(String originId) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(originId);
        PageOperation.SendKeyToElementAfterWait(driver, "originId", originId);
    }

    public void setSecurityQuestion(String question) throws Exception {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(question);
        String cssSelector = "#clientreg_securityqa";
        PageOperation.SelectCssDropDownItem(driver, cssSelector, question);
    }

    public void setSecurityAnswer(String answer) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(answer);
        PageOperation.SendKeyToElementAfterWait(driver, "securityAnswer", answer);
    }

    public void clickNextButton() throws Exception {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-profile-upgrade']/div[2]/a/span/span")).click();
        PageOperation.WebDriverWaitByXpath(driver, "//div[@id='panel-upgrade-success']");
        driver.findElement(By.xpath("//div[@id='panel-upgrade-success']"));
    }

    public void clickNextButton(String path, String regex) throws Exception {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-profile-upgrade']/div[2]/a/span/span")).click();
        validatePageContent(path, regex);
    }

}
